<template>
  <div class="hot_panel">
    <div class="hot_head">
      <div class="hot_head_logo">
        <svg-icon icon-class="fire_fill"></svg-icon>
        <span>热门资源</span>
      </div>
      <div class="hot_head_in" @click="checkInAds">
        <svg-icon icon-class="add_fill"></svg-icon>
        <span>入驻</span>
      </div>
    </div>
    <div class="hots">
      <div v-for="(hot, index) in dataList" class="hot_text" :key="index" @click="clickRsr(hot.resourceId)">
        <img :src="hot.img" />
        <span>{{ hot.resourceName }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import router from '@/router';
import settings from '@/settings';
import slotFunc from '@/mixins/rsr-slot';
export default {
  name: 's-hots',
  data() {
    return {
      dataList: null,
      // 字典
      dims: sa.$sys.getCurd(),
    }
  },
  mixins: [slotFunc],
  created: function () {
    this.getHots()
  },
  methods: {
    // 获取热门资源
    getHots() {
      sa.ajax('/rsr/hot/getSearch', function (res) {
        if (res.code === 200) {
          this.dataList = res.data
        }
      }.bind(this), {
        type: 'post'
      });
    },
    //资源入驻
    checkInAds() {
      if (sa.$sys.getToken()) {
        sa.showModel('投放资源', () => import('@/views/scs/apply/rsr'), {
          item: {}
        });
      } else {
        sa.confirm('当前未登录，是否跳转至登录页面···', function () {
          //跳转到登录
          router.replace({
            path: settings.scs_url
          })
        });
      }
    },
  }
}
</script>

<style lang="scss" scoped>
@import '@/styles/mixin.scss';

.hot_panel {
  --primary-color: #0061d8;
  --secondary-color: #ff4757;
  --text-color: #2c3e50;
  --hover-color: #00a04d;
  --gray-color: #7c7c7c;
  --tag-transition: 0.18s ease-out;
  --shadow-color: rgba(129, 129, 129, 0.08);
  --ad-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
  border-radius: 8px;
  transition:
    transform var(--ad-transition),
    box-shadow var(--ad-transition),
    background var(--ad-transition);
  will-change: transform, box-shadow;

  &:hover {
    background: linear-gradient(135deg, #f0f4f8 0%, #ffffff 100%);
    box-shadow: var(--shadow-lg);
  }
}

.hot_head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 0 8px;
}

.hot_head_logo {
  display: flex;
  align-items: center;
  color: var(--secondary-color);
  font-size: 16px;
  font-weight: 500;

  .svg-icon {
    margin-right: 8px;
    width: 20px;
    height: 20px;
  }
}

.hot_head_in {
  display: flex;
  align-items: center;
  color: var(--primary-color);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s ease;

  &:hover {
    color: var(--hover-color);
  }

  .svg-icon {
    margin-right: 4px;
    width: 16px;
    height: 16px;
  }
}

.hots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  overflow: visible;
}

.hot_text {
  display: flex;
  align-items: center;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  will-change: transform;
  transform-origin: center;

  img {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-right: 8px;
  }

  &:hover {
    color: var(--hover-color);
    font-weight: 500;
    transform: scale(1.05);
  }
}
</style>
